﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_official_info
	/// </summary>
	public partial class oa_official_info
	{
		public oa_official_info()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("ID", "oa_official_info"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_official_info");
			strSql.Append(" where ID=@ID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32)
};
			parameters[0].Value = ID;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_official_info model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_official_info(");
			strSql.Append("OfficialNo,OfficialCode,OfficialTitle,OfficialInfo,SendDeptCode,SendDeptName,SendOther,OfficialCreateDate,OfficialReleaseDate,OfficialType,OfficialStatus,HandleStatus,HandlePeople,CreatePeopleCode,CreateDate)");
			strSql.Append(" values (");
			strSql.Append("@OfficialNo,@OfficialCode,@OfficialTitle,@OfficialInfo,@SendDeptCode,@SendDeptName,@SendOther,@OfficialCreateDate,@OfficialReleaseDate,@OfficialType,@OfficialStatus,@HandleStatus,@HandlePeople,@CreatePeopleCode,@CreateDate)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@OfficialNo", MySqlDbType.VarChar,8),
					new MySqlParameter("@OfficialCode", MySqlDbType.VarChar,8),
					new MySqlParameter("@OfficialTitle", MySqlDbType.VarChar,20),
					new MySqlParameter("@OfficialInfo", MySqlDbType.VarChar,200),
					new MySqlParameter("@SendDeptCode", MySqlDbType.VarChar,100),
					new MySqlParameter("@SendDeptName", MySqlDbType.VarChar,200),
					new MySqlParameter("@SendOther", MySqlDbType.VarChar,20),
					new MySqlParameter("@OfficialCreateDate", MySqlDbType.DateTime),
					new MySqlParameter("@OfficialReleaseDate", MySqlDbType.DateTime),
					new MySqlParameter("@OfficialType", MySqlDbType.Int32,11),
					new MySqlParameter("@OfficialStatus", MySqlDbType.Int32,11),
					new MySqlParameter("@HandleStatus", MySqlDbType.Int32,11),
					new MySqlParameter("@HandlePeople", MySqlDbType.VarChar,20),
					new MySqlParameter("@CreatePeopleCode", MySqlDbType.VarChar,20),
					new MySqlParameter("@CreateDate", MySqlDbType.DateTime)};
			parameters[0].Value = model.OfficialNo;
			parameters[1].Value = model.OfficialCode;
			parameters[2].Value = model.OfficialTitle;
			parameters[3].Value = model.OfficialInfo;
			parameters[4].Value = model.SendDeptCode;
			parameters[5].Value = model.SendDeptName;
			parameters[6].Value = model.SendOther;
			parameters[7].Value = model.OfficialCreateDate;
			parameters[8].Value = model.OfficialReleaseDate;
			parameters[9].Value = model.OfficialType;
			parameters[10].Value = model.OfficialStatus;
			parameters[11].Value = model.HandleStatus;
			parameters[12].Value = model.HandlePeople;
			parameters[13].Value = model.CreatePeopleCode;
			parameters[14].Value = model.CreateDate;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_official_info model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_official_info set ");
			strSql.Append("OfficialNo=@OfficialNo,");
			strSql.Append("OfficialCode=@OfficialCode,");
			strSql.Append("OfficialTitle=@OfficialTitle,");
			strSql.Append("OfficialInfo=@OfficialInfo,");
			strSql.Append("SendDeptCode=@SendDeptCode,");
			strSql.Append("SendDeptName=@SendDeptName,");
			strSql.Append("SendOther=@SendOther,");
			strSql.Append("OfficialCreateDate=@OfficialCreateDate,");
			strSql.Append("OfficialReleaseDate=@OfficialReleaseDate,");
			strSql.Append("OfficialType=@OfficialType,");
			strSql.Append("OfficialStatus=@OfficialStatus,");
			strSql.Append("HandleStatus=@HandleStatus,");
			strSql.Append("HandlePeople=@HandlePeople,");
			strSql.Append("CreatePeopleCode=@CreatePeopleCode,");
			strSql.Append("CreateDate=@CreateDate");
			strSql.Append(" where ID=@ID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@OfficialNo", MySqlDbType.VarChar,8),
					new MySqlParameter("@OfficialCode", MySqlDbType.VarChar,8),
					new MySqlParameter("@OfficialTitle", MySqlDbType.VarChar,20),
					new MySqlParameter("@OfficialInfo", MySqlDbType.VarChar,200),
					new MySqlParameter("@SendDeptCode", MySqlDbType.VarChar,100),
					new MySqlParameter("@SendDeptName", MySqlDbType.VarChar,200),
					new MySqlParameter("@SendOther", MySqlDbType.VarChar,20),
					new MySqlParameter("@OfficialCreateDate", MySqlDbType.DateTime),
					new MySqlParameter("@OfficialReleaseDate", MySqlDbType.DateTime),
					new MySqlParameter("@OfficialType", MySqlDbType.Int32,11),
					new MySqlParameter("@OfficialStatus", MySqlDbType.Int32,11),
					new MySqlParameter("@HandleStatus", MySqlDbType.Int32,11),
					new MySqlParameter("@HandlePeople", MySqlDbType.VarChar,20),
					new MySqlParameter("@CreatePeopleCode", MySqlDbType.VarChar,20),
					new MySqlParameter("@CreateDate", MySqlDbType.DateTime),
					new MySqlParameter("@ID", MySqlDbType.Int32,11)};
			parameters[0].Value = model.OfficialNo;
			parameters[1].Value = model.OfficialCode;
			parameters[2].Value = model.OfficialTitle;
			parameters[3].Value = model.OfficialInfo;
			parameters[4].Value = model.SendDeptCode;
			parameters[5].Value = model.SendDeptName;
			parameters[6].Value = model.SendOther;
			parameters[7].Value = model.OfficialCreateDate;
			parameters[8].Value = model.OfficialReleaseDate;
			parameters[9].Value = model.OfficialType;
			parameters[10].Value = model.OfficialStatus;
			parameters[11].Value = model.HandleStatus;
			parameters[12].Value = model.HandlePeople;
			parameters[13].Value = model.CreatePeopleCode;
			parameters[14].Value = model.CreateDate;
			parameters[15].Value = model.ID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_official_info ");
			strSql.Append(" where ID=@ID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32)
};
			parameters[0].Value = ID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_official_info ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_official_info GetModel(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,OfficialNo,OfficialCode,OfficialTitle,OfficialInfo,SendDeptCode,SendDeptName,SendOther,OfficialCreateDate,OfficialReleaseDate,OfficialType,OfficialStatus,HandleStatus,HandlePeople,CreatePeopleCode,CreateDate from oa_official_info ");
			strSql.Append(" where ID=@ID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32)
};
			parameters[0].Value = ID;

			becom.Model.oa_official_info model=new becom.Model.oa_official_info();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["OfficialNo"]!=null && ds.Tables[0].Rows[0]["OfficialNo"].ToString()!="")
				{
					model.OfficialNo=ds.Tables[0].Rows[0]["OfficialNo"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OfficialCode"]!=null && ds.Tables[0].Rows[0]["OfficialCode"].ToString()!="")
				{
					model.OfficialCode=ds.Tables[0].Rows[0]["OfficialCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OfficialTitle"]!=null && ds.Tables[0].Rows[0]["OfficialTitle"].ToString()!="")
				{
					model.OfficialTitle=ds.Tables[0].Rows[0]["OfficialTitle"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OfficialInfo"]!=null && ds.Tables[0].Rows[0]["OfficialInfo"].ToString()!="")
				{
					model.OfficialInfo=ds.Tables[0].Rows[0]["OfficialInfo"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SendDeptCode"]!=null && ds.Tables[0].Rows[0]["SendDeptCode"].ToString()!="")
				{
					model.SendDeptCode=ds.Tables[0].Rows[0]["SendDeptCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SendDeptName"]!=null && ds.Tables[0].Rows[0]["SendDeptName"].ToString()!="")
				{
					model.SendDeptName=ds.Tables[0].Rows[0]["SendDeptName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SendOther"]!=null && ds.Tables[0].Rows[0]["SendOther"].ToString()!="")
				{
					model.SendOther=ds.Tables[0].Rows[0]["SendOther"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OfficialCreateDate"]!=null && ds.Tables[0].Rows[0]["OfficialCreateDate"].ToString()!="")
				{
					model.OfficialCreateDate=DateTime.Parse(ds.Tables[0].Rows[0]["OfficialCreateDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["OfficialReleaseDate"]!=null && ds.Tables[0].Rows[0]["OfficialReleaseDate"].ToString()!="")
				{
					model.OfficialReleaseDate=DateTime.Parse(ds.Tables[0].Rows[0]["OfficialReleaseDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["OfficialType"]!=null && ds.Tables[0].Rows[0]["OfficialType"].ToString()!="")
				{
					model.OfficialType=int.Parse(ds.Tables[0].Rows[0]["OfficialType"].ToString());
				}
				if(ds.Tables[0].Rows[0]["OfficialStatus"]!=null && ds.Tables[0].Rows[0]["OfficialStatus"].ToString()!="")
				{
					model.OfficialStatus=int.Parse(ds.Tables[0].Rows[0]["OfficialStatus"].ToString());
				}
				if(ds.Tables[0].Rows[0]["HandleStatus"]!=null && ds.Tables[0].Rows[0]["HandleStatus"].ToString()!="")
				{
					model.HandleStatus=int.Parse(ds.Tables[0].Rows[0]["HandleStatus"].ToString());
				}
				if(ds.Tables[0].Rows[0]["HandlePeople"]!=null && ds.Tables[0].Rows[0]["HandlePeople"].ToString()!="")
				{
					model.HandlePeople=ds.Tables[0].Rows[0]["HandlePeople"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CreatePeopleCode"]!=null && ds.Tables[0].Rows[0]["CreatePeopleCode"].ToString()!="")
				{
					model.CreatePeopleCode=ds.Tables[0].Rows[0]["CreatePeopleCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CreateDate"]!=null && ds.Tables[0].Rows[0]["CreateDate"].ToString()!="")
				{
					model.CreateDate=DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,OfficialNo,OfficialCode,OfficialTitle,OfficialInfo,SendDeptCode,SendDeptName,SendOther,OfficialCreateDate,OfficialReleaseDate,OfficialType,OfficialStatus,HandleStatus,HandlePeople,CreatePeopleCode,CreateDate ");
			strSql.Append(" FROM oa_official_info ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_official_info";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

